package com.wei.miaosha.rabbitmq;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by Weizichen on 2018/9/8.
 * desc:生产者
 */
@Service
public class MQSender {
    private static Logger logger = LoggerFactory.getLogger(MQReceiver.class);
    @Autowired
    AmqpTemplate amqpTemplate;

    public void send(Object message) {
        String msg = JSON.toJSONString(message);
        logger.info("send message" + msg);
        amqpTemplate.convertAndSend(MQconfig.MIAOSHA_QUEUE, msg);
    }

//    public void send(Object message) {
//        String msg = JSON.toJSONString(message);
//        logger.info("send message" + msg);
//        amqpTemplate.convertAndSend(MQconfig.QUEUE, msg);
//    }
//
//    public void sendTopic(Object message) {
//        String msg = JSON.toJSONString(message);
//        logger.info("send topic message" + msg);
//        amqpTemplate.convertAndSend(MQconfig.TOPIC_EXCHAGE, MQconfig.ROUTING_KEY1, msg + "1");
//        amqpTemplate.convertAndSend(MQconfig.TOPIC_EXCHAGE, MQconfig.ROUTING_KEY2, msg + "2");
//    }
//
//    public void sendFanout(Object message) {
//        String msg = JSON.toJSONString(message);
//        logger.info("send fanout message" + msg);
//        amqpTemplate.convertAndSend(MQconfig.FANOUT_EXCHAGE, msg);
//
//    }
//
//
//    public void sendHeader(Object message) {
//        String msg = JSON.toJSONString(message);
//        logger.info("send header message" + msg);
//        MessageProperties properties = new MessageProperties();
//        properties.setHeader("Header1", "Value1");
//        properties.setHeader("Header2", "Value2");
//        Message mes = new Message(msg.getBytes(),properties);
//        amqpTemplate.convertAndSend(MQconfig.HEADERS_EXCHANGE, mes);
//    }


}
